const { db, query } = require("../../db/db");
const path = require("path");
const fs = require("fs");

async function EditorUploadFile(req, res) {
  console.log("上传内容", req);
  const name = Buffer.from(req.files[0].originalname, "latin1").toString(
    "utf8"
  );
  let oldName = req.files[0].path; //获取名字
  //给新名字加上原来的后缀
  let newName = req.files[0].path + name;
  fs.renameSync(oldName, newName); //改图片的名字
  res.send({
    errno: 0,
    data: {
      alt: name,
      url: "http://localhost:6789/upload/" + req.files[0].filename + name, //该图片的预览路径
      href: "http://localhost:6789/upload/" + req.files[0].filename + name, //该图片的预览路径
    },
  });
}

module.exports = { EditorUploadFile };
